﻿using System.Collections.Generic;
using Microsoft.CodeAnalysis;

namespace Beeflys.Generator
{
    static class UTypeHelper
    {
        public static IType Create(ITypeSymbol symbol, List<string> imports, Reflect reflect)
        {
            IType item = null;


            //string name = symbol.ToString();
            //System.Console.WriteLine(name + "            " + symbol.IsValueType + "          " + symbol.IsType + "        " + symbol.IsReferenceType);
            
            //泛型特殊处理
            //if (!symbol.IsValueType && symbol.IsType && !symbol.IsReferenceType)
            //{
            //    //泛型
            //    item = new UGenericType(symbol, imports, reflect);
            //}else
            if (symbol.IsReferenceType && symbol.BaseType == null)
            {
                item = new UInterface(symbol, imports, reflect);
            }
            else if (symbol.IsReferenceType && !(symbol.BaseType.ToString() == "System.MulticastDelegate" ||
                                                 symbol.BaseType.ToString() == "System.Delegate"))
            {
                item = new UClass(symbol, imports, reflect);
            }
            else if (symbol.IsReferenceType && (symbol.BaseType.ToString() == "System.MulticastDelegate" ||
                                                symbol.BaseType.ToString() == "System.Delegate"))
            {
                item = new UDelegate(symbol, imports, reflect);
            }
            else if(!symbol.IsReferenceType && symbol.BaseType.ToString() == "System.ValueType")
            {
                item = new UStruct(symbol, imports, reflect);
            }
            else if (!symbol.IsReferenceType && symbol.BaseType.ToString() == "System.Enum")
            {
                item = new UEnum(symbol, imports, reflect);
            }

            return item;
        }
    }
}